@@ -50,7 +50,7 @@ end |
||
50 | 50 |
if (root_id = `git rev-list --max-parents=0 HEAD`.chomp) != '620acffa5a302c6a27165d3214cf3da6be6c1d0d' |
51 | 51 |
if (`git remote`.split - %w[heroku]).empty? |
52 | 52 |
puts "You don't seem to have cantino/huginn set up as upstream repository." |
53 |
- if yes?("Would you like me to set this working tree up for you?") |
|
53 |
+ if yes?("Would you like me to set this working tree up for you?", default: :yes) |
|
54 | 54 |
if system('git remote add origin https://github.com/cantino/huginn.git') && |
55 | 55 |
system('git remote update origin') |
56 | 56 |
rebase_command = "git rebase #{root_id} --onto origin/master" |
@@ -109,7 +109,7 @@ unless $config['SMTP_DOMAIN'] && $config['SMTP_USER_NAME'] && $config['SMTP_PASS |
||
109 | 109 |
end |
110 | 110 |
|
111 | 111 |
branch = capture("git rev-parse --abbrev-ref HEAD") |
112 |
-if yes?("Should I push your current branch (#{branch}) to heroku?") |
|
112 |
+if yes?("Should I push your current branch (#{branch}) to heroku?", default: :yes) |
|
113 | 113 |
puts "This may take a moment..." |
114 | 114 |
puts capture("git push heroku #{branch}:master -f") |
115 | 115 |
|
@@ -124,7 +124,7 @@ if first_time |
||
124 | 124 |
puts |
125 | 125 |
puts |
126 | 126 |
puts "I can make an admin user on your new Huginn instance and setup some example Agents." |
127 |
- if yes?("Should I create a new admin user and some example Agents?") |
|
127 |
+ if yes?("Should I create a new admin user and some example Agents?", default: :yes) |
|
128 | 128 |
done = false |
129 | 129 |
while !done |
130 | 130 |
seed_email = nag "Okay, what is your email address?" |
@@ -132,7 +132,7 @@ if first_time |
||
132 | 132 |
seed_password = nag "Finally, what password would you like to use?", noecho: true |
133 | 133 |
puts "\nJust a moment..." |
134 | 134 |
|
135 |
- result = capture("heroku run rake db:seed SEED_EMAIL=#{seed_email} SEED_USERNAME=#{seed_username} SEED_PASSWORD=#{seed_password}") |
|
135 |
+ result = capture("heroku run rake db:seed SEED_EMAIL=#{Shellwords.escape Shellwords.escape(seed_email)} SEED_USERNAME=#{Shellwords.escape Shellwords.escape(seed_username)} SEED_PASSWORD=#{Shellwords.escape Shellwords.escape(seed_password)}") |
|
136 | 136 |
if result =~ /Validation failed/ |
137 | 137 |
puts "ERROR:" |
138 | 138 |
puts |
@@ -99,7 +99,7 @@ puts "You'll need to set those environment variables in OpenShift using 'rhc env |
||
99 | 99 |
puts |
100 | 100 |
|
101 | 101 |
branch = capture("git rev-parse --abbrev-ref HEAD") |
102 |
-if first_time || yes?("Should I push your current branch (#{branch}) to OpenShift?") |
|
102 |
+if first_time || yes?("Should I push your current branch (#{branch}) to OpenShift?", default: :yes) |
|
103 | 103 |
puts "This may take a moment..." |
104 | 104 |
puts capture("git push openshift #{branch}:master -f") |
105 | 105 |
end |
@@ -112,7 +112,7 @@ if first_time |
||
112 | 112 |
puts |
113 | 113 |
puts |
114 | 114 |
puts "I can make an admin user on your new Huginn instance and setup some example Agents." |
115 |
- if yes?("Should I create a new admin user and some example Agents?") |
|
115 |
+ if yes?("Should I create a new admin user and some example Agents?", default: :yes) |
|
116 | 116 |
done = false |
117 | 117 |
while !done |
118 | 118 |
seed_email = nag "Okay, what is your email address?" |
@@ -1,6 +1,8 @@ |
||
1 | 1 |
require 'open3' |
2 | 2 |
require 'io/console' |
3 | 3 |
require 'securerandom' |
4 |
+require 'shellwords' |
|
5 |
+require 'active_support/core_ext/object/blank' |
|
4 | 6 |
|
5 | 7 |
module SetupTools |
6 | 8 |
def capture(cmd, opts = {}) |
@@ -54,7 +56,7 @@ module SetupTools |
||
54 | 56 |
end |
55 | 57 |
|
56 | 58 |
def confirm_app_name(app_name) |
57 |
- unless yes?("Your app name is '#{app_name}'. Is this correct?") |
|
59 |
+ unless yes?("Your app name is '#{app_name}'. Is this correct?", default: :yes) |
|
58 | 60 |
puts "Well, then I'm not sure what to do here, sorry." |
59 | 61 |
exit 1 |
60 | 62 |
end |
@@ -83,7 +85,11 @@ module SetupTools |
||
83 | 85 |
answer |
84 | 86 |
end |
85 | 87 |
|
86 |
- def yes?(question) |
|
87 |
- ask(question + " (y/n)") =~ /^y/i |
|
88 |
+ def yes?(question, opts = {}) |
|
89 |
+ if opts[:default].to_s[0...1] == "y" |
|
90 |
+ (ask(question + " (Y/n)").presence || "yes") =~ /^y/i |
|
91 |
+ else |
|
92 |
+ ask(question + " (y/n)") =~ /^y/i |
|
93 |
+ end |
|
88 | 94 |
end |
89 | 95 |
end |